#!/bin/sh /etc/rc.common
#by guogh

USE_PROCD=1
START=99

SPAWN_FCGI="/usr/bin/spawn-fcgi"
DAEMON="/usr/sbin/fcgiwrap"
NAME="fcgiwrap"

PIDFILE="/var/run/$NAME.pid"

FCGI_SOCKET="/tmp/$NAME.socket"
FCGI_USER="www"
FCGI_GROUP="www"
FORK_NUM=2

start_service() {
	echo -e "Starting $NAME ..."
	#procd_set_param command $SPAWN_FCGI -u $FCGI_USER -g $FCGI_GROUP -s $FCGI_SOCKET -P $PIDFILE -F $FORK_NUM -f $DAEMON
	$SPAWN_FCGI -a 127.0.0.1 -p 9000 -f $DAEMON -F $FORK_NUM
}

stop_service(){
	
	PID=`pidof $NAME`
	#i=1
	#for p in $PID
	#do
	#    if [ $i -eq 1 ]; then
	#        let i++
	#        continue
	#    fi
	#    echo -n "$p "
	#done
	#因为脚本执行时，第一个pid是脚本的，所以要去除
	if [ -n "`echo $PID | grep ' '`" ]; then
	    SPID=${PID#* }
	    echo -e "Kill $NAME (PID: $SPID)."
            kill -9 $SPID
    	else
       	    echo -e "Warning: $NAME is not runing."
	fi
	exit 0
}
restart(){
	PID=`pidof $NAME`
	#因为脚本执行时，第一个pid是脚本的，所以要去除
	if [ -n "`echo $PID | grep ' '`" ]; then
	    SPID=${PID#* }
	    echo -e "Kill $NAME (PID: $SPID)."
            kill -9 $SPID
    	else
            echo -e "Warning: $NAME is not runing."
	fi
	start_service
}





